const express = require("express")
const morgan = require("morgan")
const cors = require('cors')
const path = require('path');
const app = express()
const router = require('./router')
const errorHandler = require('./middleware/error-handler')
const bodyParser = require('body-parser');
require('./model')
app.use(cors()) //响应头
app.use(morgan('dev'))
app.use('/static', express.static(path.join(__dirname, 'public')));
app.use(express.json({ limit: "2100000kb" })) //限制json传输数据的大小
app.use(bodyParser.urlencoded({ extended: false }));
const PORT = process.env.PORT || 3000
app.use('/api',router)

//挂载异常处理
app.use(errorHandler())

app.listen(PORT,()=>{
  console.log('is running')
})